<?php
	$usty=new UserType();
	$usty->loadByKey($id);
	if ( strcasecmp( @ $_SERVER['REQUEST_METHOD'], 'POST' ) == 0 )
    {
		$list=$_POST['module'];
		
		$usty->updateDetail($conn,$list);
		
		$per=$_POST['permission'];
		foreach($list as $key => $val)
		{
			$usty->updatePermission($conn,$key,$per[$key]);
		}
		$url="?".$_SERVER['QUERY_STRING'];
		echo "<script language='JavaScript'> window.location = '".$url."'</script>";
	}
?>
<form name="f" action="" method="post">
<div class="ContentTitle">
    <div class="left" style="padding-top:8px"><?php echo $objModule->ModuleName?></div>
    <div class="CMSButton right">
        <a onclick="f.submit()">Save</a>
        <a href="?module=<?php echo $module?>">Cancel</a>
    </div>    
    <div class="clear"></div>
</div>
<ul id="ContentTabs" class="shadetabs">
    <!--
    <li><a class="selected" onclick="ShowHideDiv('Tab',1,2)">General Information</a></li>
    <li><a onclick="ShowHideDiv('Tab',1,2)">Account Information</a></li>
    -->
</ul>       

<div id="Tab1" class="TabContainer" style="display:block">
<!-------------CONTENT OF EACH MODULE ---------------------------->
<script language="javascript">
function seleteRow(ob)
{
	document.getElementById(ob.value).checked=ob.checked
	document.getElementById(ob.value+'0').checked=ob.checked
	document.getElementById(ob.value+'1').checked=ob.checked
	document.getElementById(ob.value+'2').checked=ob.checked	
}
function isFullControl(row,ob)
{
	if(document.getElementById(ob).checked==true &&document.getElementById(ob+'0').checked==true && document.getElementById(ob+'1').checked==true && document.getElementById(ob+'2').checked==true)
		document.getElementById(row).checked=true
}
</script>
<table width="100%">

<?php
	$obj=new Module();
	$data=array();
	$obj->travel("",$data);
	for($i=1;$i<count($data);$i++)
	{
		$obj->loadByKey($data[$i]);
		$check="";
		if($usty->isPermission($obj->ModuleID)!=-1)
			$check="checked";
?>
	<tr>
    	<td align="left">
        	<?php echo $obj->showDeep($obj->ModuleID,"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;")?><input type="checkbox" id="<?php echo $i?>" name="<?php echo $i?>" value="<?php echo $obj->ModuleID?>" onclick="seleteRow(this)" />Full control <input type="checkbox" id="<?php echo $obj->ModuleID?>" name="module[<?php echo $obj->ModuleID?>]" value="<?php echo $obj->ModuleID?>" <?php echo $check?>><?php echo $obj->ModuleName?>
        </td>
<?php
		$objPer=new Permission();
		$arr=$objPer->travel("");
		for($j=0;$j<count($arr);$j++)
		{
			$objPer->loadByKey($arr[$j]);
			$check="";
			if($usty->isAllow($obj->ModuleID,$objPer->PermissionID)!=-1)
				$check="checked";
?>
		<td>
        	<input type="checkbox" id="<?php echo $obj->ModuleID?><?php echo $j?>" name="permission[<?php echo $obj->ModuleID?>][<?php echo $objPer->PermissionID?>]" value="<?php echo $objPer->PermissionID?>" <?php echo $check?> /><?php echo $objPer->PermissonName;?>
        </td>
         
<?php
		}
?>
        
    </tr>
		
		

<script language="javascript">
	isFullControl('<?php echo $i?>','<?php echo $obj->ModuleID?>')
</script>
		
<?php
	}
?>
</table>

</div>
</form>